package 链表;
public class Solution2 {
    public boolean hasCycle(ListNode head) {
        if(head == null || head.next == null) {
            return false;
        }
        ListNode cur1 = head;
        ListNode cur2 = head;
        while(cur2 != null && cur2.next != null) {
            cur1 = cur1.next;
            cur2 = cur2.next.next;
            if(cur1 == cur2) {
                return true;
            }
        }
        return false;
    }
}